<?php	
/*****************************************************************************\

PHP "jeegoon.com object function " library
@function:GetMemberByID
@version: 0.1 - 12/21/2007
@author: Seraph Jiang - http://www.jeegoon.com/wordpress/
\*****************************************************************************/
	  require_once("class.member.php");	
	  require_once("class.db.jeegoon.php");	
		
	  function SetMember($p_Member,$p_Action)	
	  {	
	    if(null!=$p_Member)	
	    {	
	      try	
	      {	
	        $sh2 = new jeegoon();	
		
	        if(null!=$p_Action)	
	        {	
	          if(3 == $p_Action)	
	          {	
	            $sql="delete from member where ID='" . $p_Member["ID"] . "';";	
	            $sh2->query($sql);	
	            $sh2->query('commit');	
	            $usr = new Member();	
	            $usr->ID =$p_Member["ID"];	
	    	
	            return $usr;	
	          }	
	          else if (1 == $p_Action)	
	          {	
	            $sql="select * from member where Name='" . $p_Member["Name"] . "';";
	            $count = $sh2->querycount($sql);	
	            	
	            $salt = substr($p_Member["Password"], 0, 2);
              $encrypted_pswd = crypt($p_Member["Password"], $salt);
	            
	            if ($count==0)	
	            {	
	              $sql1 = "insert into member";
	              $sql1 = $sql1 . "(Name";
	              $sql1 = $sql1 . ",Password";
	              $sql1 = $sql1 . ",Email) ";
	              $sql1 = $sql1 . "values (";
	              $sql1 = $sql1 . "'" . $p_Member["Name"] . "'," ;	
	              $sql1 = $sql1 . "'" . $encrypted_pswd . "'," ;	
	              $sql1 = $sql1 . "'" . $p_Member["Email"] . "');" ;	
	              $result = $sh2->query($sql1);	
	              $result = $sh2->query('commit');	
	    	
	              try	
	              {	
	                $sh1 = new jeegoon();	
	                $result = $sh1->query($sql);	
	                	
	                $arr=array();	
	                $i=0;	
	                while ($line = mysql_fetch_array($result, MYSQL_BOTH)) {	
	                  $arr[$i]=$line;	
	                  $i++;	
	                }	
	                	
	                	
	                $mb = new Member();	
	                $mb->ID = $arr[0][0];	
	                $mb->Name = $arr[0][1];	
	                $mb->Password = $arr[0][2];	
	                $mb->Email = $arr[0][3];	
	                return $mb;	
	              }	
	              catch(Exception $e)	
	              {	
	                return new soap_falut('client','','SetMember Error!');	
	              	
	              }	
	            }	
	          }
            else if(2 == $p_Action)
            {
              //echo "member.id:"  . $p_Member->ID . "<br>";
              //echo $p_Member . "<br>";
              //echo "member.imgname:"  . $p_Member->imgname . "<br>";
              $sql = "";
              $sql="select * from member where ID='" . $p_Member->ID . "';";
              
              //echo "sql:"  . $sql . "<br>";
              $result = $sh2->query($sql);	
              
              $arr=array();	
              $i=0;	
              while ($line = mysql_fetch_array($result, MYSQL_BOTH)) {	
                $arr[$i]=$line;	
                $i++;	
              }	
              if($arr == null)
                return;
              
              $mb0 = new Member();
	            $mb0->ID = $arr[0][0];	
	            $mb0->Name = $arr[0][1];	
	            $mb0->Password = $arr[0][2];	
	            $mb0->Email = $arr[0][3];		
	            $mb0->imgname = $arr[0][6];
	            
              if($p_Member->Name!="")
              {
                $mb0->Name=$p_Member->Name;
              }
              if($p_Member->Password!="")
              {
                $mb0->Password=$p_Member->Password;
              }
              if($p_Member->Email!="")
              {
                $mb0->Email=$p_Member->Email;
              }
              if($p_Member->imgname!="")
              {
                $mb0->imgname=$p_Member->imgname;
                //echo $mb0->imgname . "&" . $p_Member->imgname;
              }              
	            

	              $sql1 = "update member set ";
	              $sql1 = $sql1 . "Name='" . $mb0->Name . "'";
	              $sql1 = $sql1 . ",Password='" . $mb0->Password . "'";
	              $sql1 = $sql1 . ",Email='" . $mb0->Email . "'";
	              $sql1 = $sql1 . ",imgname='" . $mb0->imgname . "'";
	              $sql1 = $sql1 . " Where ID='" . $mb0->ID . "';";
                
	              $result = $sh2->query($sql1);
	              $result = $sh2->query('commit');	
	    	
	              try	
	              {	
	                $sh1 = new jeegoon();	
	                $result = $sh1->query($sql);	
	                	
	                $arr=array();	
	                $i=0;	
	                while ($line = mysql_fetch_array($result, MYSQL_BOTH)) {	
	                  $arr[$i]=$line;	
	                  $i++;	
	                }	
	                	
	                	
	                $mb = new Member();	
	                $mb->ID = $arr[0][0];	
	                $mb->Name = $arr[0][1];	
	                $mb->Password = $arr[0][2];	
	                $mb->Email = $arr[0][3];	
	                return $mb;	
	              }	
	              catch(Exception $e)	
	              {	
	                return new soap_falut('client','','SetMember Error!');	
	              	
	              }	
	            
            }
	        }	
	      }	
	      catch(Exception $e)	
	      {	
	        return new soap_falut('client','','SetMember Error!');	
	      }	
	    }	
	    else	
	    {	
	      return new soap_falut('client','','SetMember Error!');	
	    }	
	  }	
?>
